package com.knightboy.smartshoes.outerNavigation;

import java.net.URLEncoder;

import com.baidu.location.BDLocation;

public class MakeUrl {
    //最终url地址
    private static String urlString = "";
    //目的地字符串
    private static String desString;

    /**
     * 设置目的地
     * @param destination
     */
    public static void setDesString(String destination){
        desString = destination;
    }

    /**
     * 通过目的地，现在的位置获得应向百度申请的url参数
     * @param bdLocation
     * @return
     */
    public static String makeAUrl(BDLocation bdLocation){
        StringBuffer aurl = new StringBuffer();
        try {
            aurl.append("http://api.map.baidu.com/direction/v1?mode=walking&origin=")
                    .append(bdLocation.getLatitude())
                    .append(",")
                    .append(bdLocation.getLongitude())
                    .append("&destination=")
                    .append(URLEncoder.encode(desString, "UTF-8"))
                    .append("&region=")
                    .append(URLEncoder.encode("武汉", "UTF-8"))
                    .append("&output=json&ak=" + Constants.BDak + "&mcode=" + Constants.mcode);
        } catch (Exception e) {
            e.printStackTrace();
        }
        urlString = aurl.toString();
        return urlString;
    }
}
